function addVenue(venueId) {
    var array = venueId.split("_");
    venueCounter = parseInt(array[1]) + 1;
    $(".tabBox ul li").removeClass('active');
    $(".venueContent").hide();
    $(".tabBox ul").append('<li class="active add_venue_course_show_hide_' + venueCounter + '"><a href="javascript:void(0)" id="venue_course_show_hide_' + venueCounter + '" onclick="showVenueContent(this.id);">Course Venue <span class="createdVenueCount" id="create_venue_course_show_hide_' + venueCounter + '"> 1 </span> </a></li>');
    createdVenueCount();
    $(".venueDetails").append('<div id="venue_count_' + venueCounter + '" class="venue_course_show_hide_' + venueCounter + ' venueContent">\n\
<fieldset><div class="createBox addmarginB20"><div class="padding20px"><div class="formElements"><div class="col-2"><div class="common"><input type="hidden" name="venueIndex[]" value ="' + venueCounter + '">\n\
<div class="col col1"><label>Select Venue</label> <div class="clear"></div><span style="display:none;">' + getVenueName('course_venue_venueid_' + venueCounter + '') + '</span><select name="ClassVenue[venueId][]" id="course_venue_venueid_' + venueCounter + '"  onchange="getVanueDeatils(this.id);", class="selectedVenue"></select>\n\
<p id="error_course_venue_venueid_' + venueCounter + '" class="errorMessage" style="display:none">You have already select this venue.so please select another venue!</p>\n\
</div><div class="col col2"><label for="ClassVenue_name">Name<span class="required">*</span></label><div class="clear"></div><input maxlength="45" name="ClassVenue[name][]" id="course_venue_name_' + venueCounter + '" type="text" class="requiredfield field" onblur="checkValueEmpty(this.id)">\n\
<div class="error<Message" id="error_course_venue_name_' + venueCounter + '" style="display:none">Name cannot be blank.</div></div>\n\
<div class="clear"></div></div><div class="common"><label for="ClassVenue_address_line1">Address Line1<span class="required">*</span></label><div class="clear"></div><input maxlength="45" name="ClassVenue[address_line1][]" id="course_venue_address_line1_' + venueCounter + '" type="text" class="requiredfield field" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_address_line1_' + venueCounter + '" style="display:none">Address Line1 cannot be blank.</div> <div class="clear"></div></div>\n\
<div class="common"><label for="ClassVenue_address_line2">Address Line2</label> <div class="clear"></div><input maxlength="45" name="ClassVenue[address_line2][]" id="course_venue_address_line2_' + venueCounter + '" type="text" class="field">\n\
</div><div class="common"><label for="ClassVenue_venue_locality">Locality<span class="required">*</span></label> <div class="clear"></div><input maxlength="45" name="ClassVenue[venue_locality][]" id="course_venue_venue_locality_' + venueCounter + '" type="text" class="field" onkeyup="getLocality(this.id)" onpaste="return false;">\n\
<div class="errorMessage" id="error_course_venue_venue_locality_' + venueCounter + '" style="display:none">Locality cannot be blank.</div>  <div class="errorMessage" id="error_local_course_venue_venue_locality_' + venueCounter + '"></div><div class="clear"></div></div><div class="common"><div class="col col1"> <label for="ClassVenue_zip_code">Zip Code<span class="required">*</span></label> <div class="clear"></div><input maxlength="6" name="ClassVenue[zip_code][]" id="course_venue_zip_code_' + venueCounter + '" type="text" class="requiredfield field" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_zip_code_' + venueCounter + '" style="display:none">Zip code cannot be blank.</div></div>\n\
<div class="col col2"><label for="ClassVenue_country_id" class="required">Country Name<span class="required">*</span></label><div class="clear"></div>\n\
<span style="display:none;">' + getAllCountry('course_venue_country_id_' + venueCounter + '') + '</span><select name="ClassVenue[country_id][]" id="course_venue_country_id_' + venueCounter + '" onchange="getSelectedState(this.id)"></select>\n\
<div class="errorMessage" id="error_course_venue_country_id_' + venueCounter + '" style="display:none">Country Name  code cannot be blank.</div>\n\
 </div><div class="clear"></div></div><div class="common"><div class="col col1"><label for="ClassVenue_state_id" class="required">State Name<span class="required">*</span></label>\n\
<div class="clear"></div><select name="ClassVenue[state_id][]" id="course_venue_state_id_' + venueCounter + '"  onchange="getSelectedCity(this.id)"></select>\n\
<div class="errorMessage" id="error_course_venue_state_id_' + venueCounter + '" style="display:none">State Name code cannot be blank.</div></div>\n\
<div class="col col2"><label for="ClassVenue_city_id" class="required">City Name<span class="required">*</span></label><div class="clear"></div>\n\
<select name="ClassVenue[city_id][]" id="course_venue_city_id_' + venueCounter + '"></select>\n\
<div class="errorMessage" id="error_course_venue_city_id_' + venueCounter + '" style="display:none">City Name code cannot be blank.</div></div> <div class="clear"></div>\n\
</div></div></div></div></div><div class="addbatch_venue_' + venueCounter + '_batch"><div class="venue_count' + venueCounter + '_batch_0">\n\
<div class="createBox addmarginB20"><div class="batchNum" id="venue_count' + venueCounter + '_batchShowToggle_0" onclick="showhideBatch(this.id);"><p class="remmarginB fnt-size18 font-opensansbd">Batch <span class="createdVenueBatchCount create_venue_' + venueCounter + '_batchcounter" id="create_venue_' + venueCounter + '_batch_counter_0">1</span><em class="sprite dw-arrow"></em></p></div>\n\
<div class="padding20px rempaddingT"><div class="height1px dash-borB remmarginB addmarginB20"></div>\n\
<div class="formElements">\n\
<div class="col-2"><div class="common"><div class="colcoursebatch col1"><div class="dob flatui"><label for="CourseBatche_date_from" class="required">Start Date <span class="required">*</span></label><div class="clear"></div>\n\
<input type="hidden" name="batchIndex[' + venueCounter + '][]" value="0"><input id="course_venue_' + venueCounter + '_batch_start_date_0" name="CourseBatche[ClassVenue][' + venueCounter + '][date_from][]" type="text" class="requiredfield hasDatepicker field small" onkeyup="hasDatepicker(this.id);"  onblur="checkValueEmpty(this.id)" onclick="hasDatepicker(this.id);" onpaste="return false;" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_start_date_0" style="display:none">Start date cannot be blank.</div></div>\n\
</div><div class="colcoursebatch col2"><div class="timef flatui"><label for="CourseBatche_date_to" class="required">End Date <span class="required">*</span></label><div class="clear"></div>\n\
<input name="CourseBatche[ClassVenue][' + venueCounter + '][date_to][]" id="course_venue_' + venueCounter + '_batch_end_date_0" type="text" class="hasDatepicker requiredfield field  small" onkeyup="hasDatepicker(this.id)" onclick="hasDatepicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_end_date_0" style="display:none">End date cannot be blank.</div>\n\
<div class="errorMessage" id="enddate_course_venue_' + venueCounter + '_batch_end_date_0"></div></div></div>\n\
 <div class="colcoursebatch col2"><div class="timef flatui"><label for="CourseBatche_price" class="required">Price <span class="required">*</span></label><div class="clear"></div>\n\
<input  name="CourseBatche[ClassVenue][' + venueCounter + '][price][]" id="course_venue_' + venueCounter + '_batch_price_0" type="text" onkeypress="return isNumberKey(event)" class="requiredfield field  small" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_price_0" style="display:none">Price cannot be blank.</div></div></div>\n\
<div class="colcoursebatch col2"><div class="timef flatui"><label for="CourseBatche_seats" class="required">Seats <span class="required">*</span></label><div class="clear"></div>\n\
<input  name="CourseBatche[ClassVenue][' + venueCounter + '][seats][]" id="course_venue_' + venueCounter + '_batch_seats_0" type="text" onkeypress="return isNumberKey(event)" class="requiredfield field  small" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_seats_0" style="display:none">Seats cannot be blank.</div>\n\
</div></div> <div class="clear"></div></div><div class="greenBor"><p class="padding20px remmarginB font-opensansbd fnt-size16">Batch Discounts</p>\n\
<div class="dash-borB height1px"></div><div class="padding20px"><div id="venue_' + venueCounter + '_batch_0_earlydiscount"></div>\n\
<div class="common"><p class="alignL remmarginB"><a href="javascript:void(0)" id="venue_' + venueCounter + '_batch_0_earlydiscount_0" onclick="addEarlyDiscount(this.id);">+ Add Early Discounts</a></p></div>\n\
<div class="height1px borB addmarginB30 rempaddingB"></div> <div id="venue_' + venueCounter + '_batch_0_groupdiscount"></div>\n\
<div class="common"><p class="alignL remmarginB"><a href="javascript:void(0)" id="venue_' + venueCounter + '_batch_0_groupdiscount_0" onclick="addGroupDiscount(this.id);">+ Add Group Discounts</a></p></div>\n\
<div class="height1px borB addmarginB30 rempaddingB"></div></div></div>\n\
<div class="clear"></div><div class="common"> <div class="padding20px"><input type="radio" class="venue_'+ venueCounter +'_batch_0_fancyRadio" id="venue_' + venueCounter + '_batch_0_daySession_show_hide" name="days_venue_' + venueCounter + '_batch_0" checked="checked"><label>Days of the week</label>\n\
 <input type="radio" class="venue_'+ venueCounter +'_batch_0_fancyRadio" id="venue_' + venueCounter + '_batch_0_dateSession" name="days_venue_' + venueCounter + '_batch_0"><label>Number of Sessions</label></div></div>\n\
 <div class="common"><div class="greenBor"><p class="padding20px remmarginB font-opensansbd fnt-size16">Batch Sessions</p>\n\
<div class="dash-borB height1px"></div><div class="venue_' + venueCounter + '_batch_0_daySession_show_hide"> <div class="padding20px"><div class="insm-col1"><label>Select Day</label>\n\
<div class="clear"></div><select name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][schedule_id][]" id="course_venue_' + venueCounter + '_batch_0_daySession_schedule_id_0" class="requiredfield">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"> <label>Start Time</label><div class="clear"></div> \n\
<input  name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][time_from][]" id="course_venue_' + venueCounter + '_batch_0_daySession_time_from_0" type="text"  class="hastimePicker requiredfield  field small" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="timeCheck(this.id);"> \n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_time_from_0" style="display:none">Start time cannot be blank.</div> </div>\n\
<div class="insm-col2 bootstrap-timepicker"><label>End Time</label> <div class="clear"></div> <input name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][time_to][]" id="course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" class="hastimePicker requiredfield  field small" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text"   size="10" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" ></div></div>\n\
<div class="insm-col3 "><label style="margin:4px 0px 15px 9px">Flexible</label><div class="clear"></div>\n\
<input type="checkbox" class="fancyCheckBox" value="1" id="course_venue_' + venueCounter + '_batch_0_daySession_is_flexible_0" onclick="return isFlexibleDaySession(this.id);" name="CourseBatcheDaySessions[CourseBatche][0][ClassVenue][' + venueCounter + '][is_flexible][]" >\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueCounter + '_batch_0_daySession_is_flexiblevalue_0"/>\n\
</div><div class="clear"></div></div> </div><div class="venue_' + venueCounter + '_batch_0_daySession"></div><div class="padding20px venue_' + venueCounter + '_batch_0_dateNoSession" style="display: none;"> <div class="formElements">\n\
<div class="col col-1"> <label>No. of Sessions<em class="sprite question-sign">&nbsp;</em></label>\n\
 <input type="text" class="field" name="CourseBatche[ClassVenue][' + venueCounter + '][no_of_session][]" id="no_of_session_venue_' + venueCounter + '_batch_0" onchange="return dateSessionValue(this.id);" onkeyup="return dateSessionValue(this.id);" onkeypress="return isNumberKey(event);" placeholder="0"  maxlength="2">\n\
</div><div class="clear"></div></div></div><div class="venue_' + venueCounter + '_batch_0_dateSession" style="display: none;"></div><div class="dash-borB height1px"></div><div class="venue_' + venueCounter + '_batch_0_daySession_addSesion">\n\
 <div class="padding20px"> <a class="floatR" href="javascript:void(0);" onclick="addDaySession(this.id);" id="venue_' + venueCounter + '_batch_0_daySession_0">+Add More</a>\n\
 <div class="clear"></div></div></div></div> </div> <div class="greenBor" style="margin-top: 10px;"><p class="padding20px remmarginB font-opensansbd fnt-size16">Class Structure</p>\n\
  <div class="dash-borB height1px addmarginB20"></div> <div class="formElements"><div class="col-2 borB addmarginB20">\n\
<div class="padding20px"> <div id="venue_' + venueCounter + '_batch_0_classStructures"><div class="common">\n\
<div class="colstructure col2"><div class="timef flatui"><label for="ClassStructures_start_time">Start Time</label><div class="clear"></div>\n\
<div class="input-append"> <input name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][start_time][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_start_time_0" type="text" class="field small" placeholder="0" maxlength="3" value="0" readonly="readonly"><span class="add-on">Min</span>\n\
</div></div></div><div class="colstructure col2"><div class="timef flatui"><label for="ClassStructures_end_time">End Time</label><div class="clear"></div>\n\
<div class="input-append"><input type="hidden" name="addclassStructure" id="class_venue_' + venueCounter + '_classbatch_0_struct_struct_count_0" value="0" class="class_venue_' + venueCounter + '_classbatch_0_startDatecount">\n\
<input onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][end_time][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_end_time_0" type="text" class="field small" maxlength="2" onblur="addValueInclassStructureStartTime(this.id)"><span class="add-on">Min</span>\n\
</div></div></div><div class="clear"></div></div><div class="common"><label for="ClassStructures_description">Description</label>\n\
<div class="clear"></div><textarea name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][description][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_struct_description_0"> </textarea>\n\
<div class="clear"></div></div><div class="height1px borB addmarginB30 rempaddingB"></div></div>\n\
<div class="common"><p class="alignR remmarginB"><a href="javascript:void(0)" class="btn-green class_venue_' + venueCounter + '_classbatch_0_add_structure" id="class_venue_' + venueCounter + '_classbatch_0_struct_add_count_0" onclick="addclassStructures(this.id);">Add Structures</a></p>\n\
</div></div></div></div></div></div></div></div></div></div></div>\n\
<div class="addOpt addmarginB20"><div class="padding20px"><div class="floatL"><h4 class="txttTransformNorml txtfff">Batch Details</h4></div>\n\
<div class="floatR"><a href="javascript:void(0)" class="btn-green" id="venue_' + venueCounter + '_batch_0" onclick="addBatch(this.id);">Add Batch</a></div>\n\
<div class="clear"></div></div></div><div class="addOpt addmarginB20"><div class="padding20px">\n\
<div class="floatL"><a href="javascript:void(0)" class="btn-red" id="venue_remove_' + venueCounter + '" onclick="reMoveVenue(this.id);">Remove Venue</a></div>\n\
<div class="clear"></div></div> </div></fieldset></div>');
    $("#" + venueId).attr('id', 'venue_' + venueCounter);
    $("#course_venue_" + venueCounter + "_batch_0_daySession_is_flexible_0").fancyfields({
        onCheckboxChange: function (input, isChecked){            
            datedaySesionisFlexble(input.attr("id"),isChecked); 
        }
    } );
    $('.venue_'+ venueCounter +'_batch_0_fancyRadio').fancyfields({
        onRadioChange: function (input){          
            showDateSessionAndDaySesion(input.attr("id"));
        }
    });
    
}

function reMoveVenue(venueId) {
    array = venueId.split("_");
    $('#venue_count_' + array[2]).remove();
    $('.add_venue_course_show_hide_' + array[2]).remove();
    createdVenueCount();
    $('.add_venue_course_show_hide_0').addClass('active');
    $('.venue_course_show_hide_0').show();
}

function addBatch(batchVenueId) {
    var array = batchVenueId.split("_");
    batchCounter = parseInt(array[3]) + 1;
    venueIndex = array[1];
    $(".contenttoggleClass").hide();
    $(".content").hide();
    $('.addbatch_venue_' + venueIndex + '_batch').append('<div id="venue_count' + venueIndex + '_batch_' + batchCounter + '">\n\
    <div class="createBox addmarginB20"> <div class="batchNum" id="venue_count' + venueIndex + '_batchShowToggle_' + batchCounter + '" onclick="showhideBatch(this.id);"> \n\
<p class="remmarginB fnt-size18 font-opensansbd">Batch <span class="createdVenueBatchCount create_venue_' + venueIndex + '_batchcounter" id="create_venue_' + venueIndex + '_batch_counter_' + batchCounter + '">\n\
1</span><em class="sprite dw-arrow"></em></p></div><div class="contenttoggleClass venue_count' + venueIndex + '_batchShowToggle_' + batchCounter + '"><div class="padding20px rempaddingT">\n\
<div class="height1px dash-borB remmarginB addmarginB20"></div> <div class="formElements"><div class="col-2"><div class="common"><div class="colcoursebatch col1"><div class="dob flatui">\n\
<label for="CourseBatche_date_from" class="required">Start Date <span class="required">*</span></label><div class="clear"></div>\n\
<input type="hidden" name="batchIndex[' + venueIndex + '][]" value="' + batchCounter + '">\n\
<input id="course_venue_' + venueIndex + '_batch_start_date_' + batchCounter + '" name="CourseBatche[ClassVenue][' + venueIndex + '][date_from][]" type="text" class="requiredfield hasDatepicker field small" onkeyup="hasDatepicker(this.id);" onblur="checkValueEmpty(this.id)" onclick="hasDatepicker(this.id);" onpaste="return false;" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_start_date_' + batchCounter + '" style="display:none">Start date cannot be blank.</div></div>\n\
</div><div class="colcoursebatch col2"><div class="timef"><label for="CourseBatche_date_to" class="required">End Date <span class="required">*</span></label><div class="clear"></div>\n\
<input name="CourseBatche[ClassVenue][' + venueIndex + '][date_to][]" id="course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '" type="text" class="hasDatepicker requiredfield field  small" onkeyup="hasDatepicker(this.id)" onclick="hasDatepicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '" style="display:none">End date cannot be blank.</div>\n\
<div class="errorMessage" id="enddate_course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '"></div></div></div>\n\
 <div class="colcoursebatch col2"><div class="timef flatui"><label for="CourseBatche_price" class="required">Price <span class="required">*</span></label><div class="clear"></div>\n\
<input name="CourseBatche[ClassVenue][' + venueIndex + '][price][]" id="course_venue_' + venueIndex + '_batch_price_' + batchCounter + '" type="text" onkeypress="return isNumberKey(event)" class="requiredfield field  small" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_price_' + batchCounter + '" style="display:none">Price cannot be blank.</div></div></div>\n\
<div class="colcoursebatch col2"><div class="timef flatui"><label for="CourseBatche_seats" class="required">Seats <span class="required">*</span></label><div class="clear"></div>\n\
<input name="CourseBatche[ClassVenue][' + venueIndex + '][seats][]" id="course_venue_' + venueIndex + '_batch_seats_' + batchCounter + '" type="text" onkeypress="return isNumberKey(event)" class="requiredfield field  small" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_seats_' + batchCounter + '" style="display:none">Seats cannot be blank.</div>\n\
</div></div> <div class="clear"></div></div><div class="greenBor"><p class="padding20px remmarginB font-opensansbd fnt-size16">Batch Discounts</p>\n\
<div class="dash-borB height1px"></div><div class="padding20px"><div id="venue_' + venueIndex + '_batch_' + batchCounter + '_earlydiscount"></div>\n\
<div class="common"><p class="alignL remmarginB"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchCounter + '_earlydiscount_0" onclick="addEarlyDiscount(this.id);">+ Add Early Discounts</a></p></div>\n\
<div class="height1px borB addmarginB30 rempaddingB"></div> <div id="venue_' + venueIndex + '_batch_' + batchCounter + '_groupdiscount"></div>\n\
<div class="common"><p class="alignL remmarginB"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchCounter + '_groupdiscount_0" onclick="addGroupDiscount(this.id);">+ Add Group Discounts</a></p></div>\n\
<div class="height1px borB addmarginB30 rempaddingB"></div></div></div>\n\
<div class="clear"></div><div class="common"> <div class="padding20px">\n\
<input type="radio" class="venue_'+ venueIndex +'_batch_' + batchCounter+'_fancyRadio"  id="venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_show_hide" name="days_venue_' + venueIndex + '_batch_'+batchCounter+'" checked="checked"><label>Days of the week</label>\n\
<input type="radio" class="venue_'+ venueIndex +'_batch_' + batchCounter+'_fancyRadio"  id="venue_' + venueIndex + '_batch_'+batchCounter+'_dateSession" name="days_venue_' + venueIndex + '_batch_'+batchCounter+'"><label>Number of Sessions</label> </div> </div>\n\
 <div class="common"><div class="greenBor"><p class="padding20px remmarginB font-opensansbd fnt-size16">Batch Sessions</p>\n\
<div class="dash-borB height1px"></div><div class="venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_show_hide"> <div class="padding20px"><div class="insm-col1"><label>Select Day</label>\n\
<div class="clear"></div><select name="CourseBatcheDaySession[CourseBatche]['+batchCounter+'][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_schedule_id_0" class="requiredfield">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\
<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"> <label>Start Time</label><div class="clear"></div>\n\
<input  name="CourseBatcheDaySession[CourseBatche]['+batchCounter+'][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_time_from_0" type="text"  class="hastimePicker requiredfield  field small" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="timeCheck(this.id)"> \n\
<div class="errorMessage" id="error_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_time_from_0" style="display:none">Start time cannot be blank.</div> </div>\n\
<div class="insm-col2 bootstrap-timepicker"><label>End Time</label> <div class="clear"></div> <input name="CourseBatcheDaySession[CourseBatche]['+batchCounter+'][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_time_to_0" class="hastimePicker requiredfield  field small" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text"  size="10" onchange="timeCheck(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
<div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_time_to_0"></div></div>\n\
<div class="insm-col3 "><label style="margin:4px 0px 15px 9px">Flexible</label><div class="clear"></div>\n\
<input type="checkbox" class="fancyCheckBox" value="1" id="course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_is_flexible_0" onclick="return isFlexibleDaySession(this.id);" name="CourseBatcheDaySessions[CourseBatche]['+batchCounter+'][ClassVenue][' + venueIndex + '][is_flexible][]" >\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche]['+batchCounter+'][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_is_flexiblevalue_0"/>\n\
 </div><div class="clear"></div> </div></div><div class="venue_' + venueIndex + '_batch_'+batchCounter+'_daySession"></div>\n\
<div class="padding20px venue_' + venueIndex + '_batch_'+batchCounter+'_dateNoSession" style="display: none;"><div class="formElements">\n\
<div class="col col-1"> <label>No. of Sessions<em class="sprite question-sign">&nbsp;</em></label>\n\
<input type="text" class="field" name="CourseBatche[ClassVenue][' + venueIndex + '][no_of_session][]" id="no_of_session_venue_' + venueIndex + '_batch_'+batchCounter+'" onchange="return dateSessionValue(this.id);" onkeyup="return dateSessionValue(this.id);" onkeypress="return isNumberKey(event);" placeholder="0"  maxlength="2">\n\
</div><div class="clear"></div></div></div><div class="venue_' + venueIndex + '_batch_'+batchCounter+'_dateSession" style="display: none;"></div><div class="dash-borB height1px"></div><div class="venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_addSesion">\n\
<div class="padding20px"> <a class="floatR" href="javascript:void(0);" onclick="addDaySession(this.id);" id="venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_0">+Add More</a>\n\
<div class="clear"></div></div></div></div> </div></div></div><div class="greenBor" style="margin-top: 10px;">\n\
<p class="padding20px remmarginB font-opensansbd fnt-size16">Class Structure</p><div class="dash-borB height1px addmarginB20"></div>\n\
<div class="formElements"><div class="col-2 borB addmarginB20"><div class="padding20px">\n\
<div id="venue_' + venueIndex + '_batch_'+batchCounter+'_classStructures"><div class="common">\n\
 <div class="colstructure col2"><div class="timef flatui"><label for="ClassStructures_start_time">Start Time</label>\n\
<div class="clear"></div><div class="input-append"><input name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch]['+batchCounter+'][start_time][]" id="class_venue_' + venueIndex + '_batch_'+batchCounter+'_struct_start_time_0" type="text" class="field small" placeholder="0" maxlength="3" value="0" readonly="readonly"><span class="add-on">Min</span>\n\
</div></div></div><div class="colstructure col2"><div class="timef flatui"><label for="ClassStructures_end_time">End Time</label>  \n\
<div class="clear"></div>\n\
<input type="hidden" name="addclassStructure" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_struct_count_0" value="0" class="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_startDatecount">\n\
<div class="input-append"><input onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch][' + batchCounter + '][end_time][]" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_end_time_0" type="text" class="field small" maxlength="2" onblur="addValueInclassStructureStartTime(this.id)"><span class="add-on">Min</span>\n\
 </div> </div> </div><div class="clear"></div> </div><div class="common">\n\
<label for="ClassStructures_description">Description</label> <div class="clear"></div>\n\
 <textarea name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch][' + batchCounter + '][description][]" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_struct_description_0"> </textarea>\n\
<div class="clear"></div></div><div class="height1px borB addmarginB30 rempaddingB"></div>\n\
</div> <div class="common"><p class="alignR remmarginB"><a href="javascript:void(0)" class="btn-green class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_add_structure" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_add_count_0" onclick="addclassStructures(this.id);">Add Structures</a></p>\n\
</div> </div></div></div></div></div><p class="alignL padding20px remmarginB"><a href="javascript:void(0)" id="venue_remove_' + venueIndex + '_batch_' + batchCounter + '" onclick="reMoveBatch(this.id);">-Remove Batch</a></p></div></div></div>\n\
');
    $("#" + batchVenueId).attr('id', 'venue_' + venueIndex + '_batch_' + batchCounter);
    createdBatchCount('create_venue_' + venueIndex + '_batchcounter');
    $('#course_venue_' + venueIndex + '_batch_'+batchCounter+'_daySession_is_flexible_0').fancyfields({
        onCheckboxChange: function (input, isChecked){            
            datedaySesionisFlexble(input.attr("id"),isChecked); 
        }
    } );
    $('.venue_'+ venueIndex +'_batch_' + batchCounter+'_fancyRadio').fancyfields({
        onRadioChange: function (input){          
            showDateSessionAndDaySesion(input.attr("id"));
        }
    });
    
}


function reMoveBatch(batchId) {
    var array = batchId.split("_");
    $('#venue_count' + array[2] + '_batch_' + array[4]).remove();
    createdBatchCount('create_venue_' + array[2] + '_batchcounter');
}

function addEarlyDiscount(earlyDiscountId) {
    var array = earlyDiscountId.split("_");
    earlyCounter = parseInt(array[5]) + 1;
    venueIndex = array[1];
    batchIndex = array[3];
    $('#venue_' + venueIndex + '_batch_' + batchIndex + '_earlydiscount').append('<div id="venue_' + venueIndex + '_batch_' + batchIndex + '_earlyCount_' + earlyCounter + '">\n\
<div class="sm-col-2 addmarginB20"><div class="common"> \n\
<div class="colEarly col1"><input onblur="checkValueEmpty(this.id);" onchange="enableDisableEarlyBirdTextField(this.id);"  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_price][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_discount_price_' + earlyCounter + '" type="text" placeholder="Discount Price" onkeypress="return isNumberKey(event)"   class="requiredfield field small">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_discount_price_' + earlyCounter + '" style="display:none">Discount price is required.</div></div>\n\
<div class="colEarly col2"><input onblur="checkValueEmpty(this.id);" onchange="enableDisableEarlyBirdTextField(this.id);"  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][in_percentage][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_in_percentage_' + earlyCounter + '" type="text" placeholder="In Percentage" onkeypress="return isNumberKey(event)"   class="requiredfield field small">\n\
<div class="errorMessage" id="error_class_venue_' + venueIndex + '_batch_' + batchIndex + '_early_in_percentage_' + earlyCounter + '" style="display:none">Percentage is required.</div></div>\n\
<div class="colEarly col2"><input  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][valid_to][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_valid_to_' + earlyCounter + '" class="hasDatepicker requiredfield  field small" onkeyup="hasDatepicker(this.id);"  onclick="hasDatepicker(this.id);" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text" placeholder="Valid To" readonly="readonly" size="10">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_valid_to_' + earlyCounter + '" style="display:none">Valid to is required.</div></div>\n\
<div class="colEarlylast col2"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchIndex + '_earlyRemove_' + earlyCounter + '" onclick="removeEarlyDiscount(this.id);">-Remove</a></div>\n\
 <div class="clear"></div></div></div>');
    $("#" + earlyDiscountId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex + '_earlydiscount_' + earlyCounter + '');
}

function removeEarlyDiscount(removeEarly) {
    var array = removeEarly.split("_");
    $('#venue_' + array[1] + '_batch_' + array[3] + '_earlyCount_' + array[5] + '').remove();
}

function addGroupDiscount(groupDiscountId) {
    var array = groupDiscountId.split("_");
    groupCounter = parseInt(array[5]) + 1;
    venueIndex = array[1];
    batchIndex = array[3];
    $('#venue_' + venueIndex + '_batch_' + batchIndex + '_groupdiscount').append('<div id="venue_' + venueIndex + '_batch_' + batchIndex + '_groupCount_' + groupCounter + '">\n\
 <div class="sm-col-2 addmarginB20"><div class="common">\n\
<div class="colEarly col1">\n\
<input  onchange="enableDisableGroupDiscountTextField(this.id);"  name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_amount][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_discount_amount_' + groupCounter + '" onblur="checkValueEmpty(this.id);" type="text" placeholder="Discount Amount" onkeypress="return isNumberKey(event)" class="requiredfield field small">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_discount_amount_' + groupCounter + '" style="display:none">Discount is required.</div></div>\n\
<div class="colEarly col2"><input  onchange="enableDisableGroupDiscountTextField(this.id);" name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_in_percentage][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_in_percentage_' + groupCounter + '" onblur="checkValueEmpty(this.id);" type="text" placeholder="Discount in percentage" onkeypress="return isNumberKey(event)" class="requiredfield field small">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_in_percentage_' + groupCounter + '" style="display:none">Amount is required.</div></div>\n\
<div class="colEarly col2"><input  name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][group_size][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_size_' + groupCounter + '" type="text" placeholder="Group Size" onblur="checkValueEmpty(this.id)" onkeypress="return isNumberKey(event)" class="requiredfield field small">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_size_' + groupCounter + '" style="display:none">Group Size is required.</div></div>\n\
<div class="colEarlylast col2"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchIndex + '_groupRemove_' + groupCounter + '" onclick="removeGroupDiscount(this.id);">-Remove</a></div>\n\
<div class="clear"></div></div></div>');
    $("#" + groupDiscountId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex + '_groupdiscount_' + groupCounter + '');
}

function removeGroupDiscount(removeGroup) {
    var array = removeGroup.split("_");
    $('#venue_' + array[1] + '_batch_' + array[3] + '_groupCount_' + array[5] + '').remove();
}
function enableDisableEarlyBirdTextField(id) {
    var array = id.split("_");
    var inPericentageId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_early_discount_price_' + array[8] + '';
    var inDiscountPriceId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_early_in_percentage_' + array[8] + '';
    var inDiscountPriceVal = $("#" + inDiscountPriceId).val();
    var inPericentageVal = $("#" + inPericentageId).val();
    if (inDiscountPriceId == id && inDiscountPriceVal != '')
    {
        $("#" + inPericentageId).attr("readonly", "readonly");
        $("#" + inPericentageId).removeClass("requiredfield");
        $("#" + inPericentageId).removeAttr('style');
    }
    else if (inPericentageId == id && inPericentageVal != '') {
        $("#" + inDiscountPriceId).attr("readonly", "readonly");
        $("#" + inDiscountPriceId).removeClass("requiredfield");
        $("#" + inDiscountPriceId).removeAttr('style');
    }
    else if (inDiscountPriceVal == '' && inPericentageVal == '') {
        $("#" + inDiscountPriceId).removeAttr("readonly");
        $("#" + inPericentageId).removeAttr("readonly");
        $("#" + inPericentageId).addClass("requiredfield");
        $("#" + inDiscountPriceId).addClass("requiredfield");
    }

}

function enableDisableGroupDiscountTextField(id) {
    var array = id.split("_");
    var inPericentageId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_group_in_percentage_' + array[8] + '';
    var inDiscountPriceId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_group_discount_amount_' + array[8] + '';
    var inDiscountPriceVal = $("#" + inDiscountPriceId).val();
    var inPericentageVal = $("#" + inPericentageId).val();
    if (inDiscountPriceId == id && inDiscountPriceVal != '')
    {
        $("#" + inPericentageId).attr("readonly", "readonly");
        $("#" + inPericentageId).removeClass("requiredfield");
        $("#" + inPericentageId).removeAttr('style');
    }
    else if (inPericentageId == id && inPericentageVal != '') {
        $("#" + inDiscountPriceId).attr("readonly", "readonly");
        $("#" + inDiscountPriceId).removeClass("requiredfield");
        $("#" + inDiscountPriceId).removeAttr('style');
    }
    else if (inDiscountPriceVal == '' && inPericentageVal == '') {
        $("#" + inDiscountPriceId).removeAttr("readonly");
        $("#" + inPericentageId).removeAttr("readonly");
        $("#" + inPericentageId).addClass("requiredfield");
        $("#" + inDiscountPriceId).addClass("requiredfield");
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function hasDatepicker(id) {
    $("#" + id).attr('readonly', 'readonly');
    $("#" + id).removeClass('hasDatepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        showAnim: 'fold',
        showButtonPanel: false,
        autoSize: true,
        dateFormat: 'yy-mm-dd',
        minDate: 0,
        maxDate: 90
    }).focus();
}

function hastimePicker(id) {  
    $("#" + id).attr('readonly', 'readonly');
    $("#" + id).removeClass('hasDatepicker').timepicker({
        minuteGrid: 10, 
        timeFormat: 'hh:mm tt', 
        ampm: true
    });
}

function addclassStructures(id) {
    var array = id.split("_"); 
    var startTimeVal = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + array[8] + '').val();
    var classStructures = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + array[8] + '').val(array[8]);
    var classStructures = parseInt(array[8]) + 1;
    $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + classStructures + '');
    $('#venue_' + array[2] + '_batch_' + array[4] + '_classStructures').append('<div class="classStructureControl" id="remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" >\n\
<div class="common"><div class="colstructure col2"><div class="timef flatui">\n\
 <label>Start Time</label><div class="clear"></div>\n\
<div class="input-append"><input class="field small"  onkeypress="return isNumberKey(event)" maxlength="3" name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][start_time][]" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + classStructures + '" type="text" readonly="readonly" maxlength="2" value=' + startTimeVal + ' ><span class="add-on">Min</span></div></div></div>\n\
<div class="colstructure col2"> <div class="timef flatui"><label>End Time</label><div class="clear"></div>\n\
<div class="input-append"> <input class="field small enddateCount" onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][end_time][]" maxlength="2" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + classStructures + '" type="text" onblur="addValueInclassStructureStartTime(this.id);" ><span class="add-on">Min</span></div></div></div>\n\
<div class="clear"></div></div>\n\
<div class="common"><label>Description</label> <div class="clear"></div>\n\
<textarea  name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][description][]" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + classStructures + '" ></textarea>\n\
<input type="hidden" class="class_venue_' + array[2] + '_classbatch_' + array[4] + '_startDatecount" name="addclassStructure" class="addclassStructurecount" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + classStructures + '" value="' + classStructures + '"><div class="clear"></div></div>\n\
<div class="height1px borB addmarginB30 rempaddingB"></div><div class="common"> <p class="alignR remmarginB"><a href="javascript:void(0)" class="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" onclick="removeclassStructures(this.id);">-Remove</a></p></div></div>');
}

function addValueInclassStructureStartTime(id) {
    var array = id.split("_");
    var endTimeId = parseInt(array[8]) + 1;
    var startTimeVal = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + endTimeId + '').val($("#" + id).val());
}

function removeclassStructures(structid) {
    var i = 0;
    var arrayVal = structid.split("_");
    $("div #remove_" + structid).remove();
    $(".class_venue_" + arrayVal[2] + "_classbatch_" + arrayVal[4] + "_startDatecount").each(function() {
        array = this.id.split("_");
        $("#" + this.id).attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + i).val(i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + i);
        $('#remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + array[8] + '').attr('id', 'remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + i);
        i++;
    });
    var totalCount = parseInt(i) - 1;
    $('.class_venue_' + array[2] + '_classbatch_' + array[4] + '_add_structure').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + totalCount);

}
function addSesionOnRadioChange(sessionId){
    var array = sessionId.split("_");   
    batchIndex = parseInt(array[3]);
    venueIndex = array[1]; 
    $('Div .venue_'+venueIndex+'_batch_'+batchIndex+'_daySession_show_hide').html('<div class="padding20px"><div class="insm-col1">\n\
<label>Select Day</label> <div class="clear"></div><select name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_0" class=" requiredfield course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_0">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"><label>Start Time</label> <div class="clear"></div><input class="hastimePicker requiredfield  field small" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_from_0" type="text" placeholder="Start Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_from_0" style="display:none">Start time cannot be blank.</div></div> <div class="insm-col2 bootstrap-timepicker">\n\
<label>End Time</label><div class="clear"></div><input class="hastimePicker requiredfield  field small" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_0" type="text" placeholder="End Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_0"></div></div><div class="insm-col3 ">\n\
 <label style="margin:4px 0px 15px 9px">Flexible</label><div class="clear"></div>\n\
<input type="checkbox" class="isdaySesionFlexble" value="1" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_is_flexible_0" onclick="return isFlexibleDaySession(this.id);" name="CourseBatcheDaySessions[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexible][]" >\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_is_flexiblevalue_0"/></div><div class="clear"></div></div>  ');
    $('.isdaySesionFlexble').fancyfields({
        onCheckboxChange: function (input, isChecked){            
            datedaySesionisFlexble(input.attr("id"),isChecked);
        }
    });

}


function addDaySession(sessionId) {
    var array = sessionId.split("_");
    var addDayCounter = parseInt(array[5]);
    var addDaySessionCounter = parseInt(addDayCounter)+1;
    batchIndex = parseInt(array[3]);
    venueIndex = array[1];
    $('Div .venue_'+venueIndex+'_batch_'+batchIndex+'_daySession').append('<div class="venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_' + addDaySessionCounter + '">\n\
<div class="clear"></div><div class="padding20px"><div class="insm-col1"><select name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_' + addDaySessionCounter + '" class=" requiredfield course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_' + addDaySessionCounter + '">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_schedule_id_' + addDaySessionCounter + '" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"><div class="clear"></div> <input class="hastimePicker requiredfield  field small" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_from_' + addDaySessionCounter + '" type="text" placeholder="Start Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_from_' + addDaySessionCounter + '" style="display:none">Start time cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"><div class="clear"></div> <input class="hastimePicker requiredfield  field small" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_' + addDaySessionCounter + '" type="text" placeholder="End Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_' + addDaySessionCounter + '" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_'+batchIndex+'_daySession_time_to_' + addDaySessionCounter + '"></div></div>\n\
<div class="insm-col3 customeform"><div class="clear"></div><input type="checkbox" class="fancyCheckBox" name="CourseBatcheDaySessions[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexible][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexible_' + addDaySessionCounter + '" onclick="return isFlexibleDaySession(this.id);">\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexiblevalue_' + addDaySessionCounter + '"/>\n\
<p class="isFlexbleRemove"><a class="link-remove" id="remove_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_' + addDaySessionCounter + '" onclick="removeDaySession(this.id);"><span>Remove</span></a></p></div></div> <div class="clear"></div> </div>');
    $("#course_venue_" + venueIndex + "_batch_" + batchIndex + "_daySession_is_flexible_" + addDaySessionCounter).fancyfields({
        onCheckboxChange: function (input, isChecked){            
            datedaySesionisFlexble(input.attr("id"),isChecked);
        }
    });
    $("#" + sessionId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex+'_daySession_'+addDaySessionCounter);
}

function removeDaySession(BatchDaySessionId) {
    var array = BatchDaySessionId.split("_");
    $('Div .venue_' + array[2] + '_batch_' + array[4] + '_daySession_' + array[6] + '').remove();
}

function createdVenueCount() {
    var i = 1;
    $('.createdVenueCount').each(function() {
        $("#" + this.id).text(i);
        i++;
    })
}

function checkValueEmpty(id) {
    ($("#" + id).val() != '') ? $("#error_" + id).hide() : $("#error_" + id).show();
}

function createdBatchCount(batchId) {
    var i = 1;
    $('.' + batchId).each(function() {
        $("#" + this.id).text(i);
        i++;
    })
}
function dateSessionValue(id){   
    var dataSessionval= $("#" + id).val();
    var dateSessionhtml = "";
    array=id.split("_");
    if(dataSessionval >'0' && dataSessionval < 40){
        dateSessionhtml += '<div class="padding20px"><div class="insm-col1"><label>Start date</label><div class="clear"></div></div>\n\
<div class="insm-col2"><label>Start Time</label><div class="clear"></div></div>\n\
<div class="insm-col2"><label>End Time</label><div class="clear"></div></div>\n\
<div class="insm-col3 "> <label style="margin:4px 0px 15px 9px">Flexible</label> <div class="clear"></div></div>';
        for (var i = 1; i <= dataSessionval; i++) {
            dateSessionhtml += '<div class="insm-col1 "> \n\
<input class="field small requiredfield" onpaste="return false;" onclick="hasDatepicker(this.id)" name="CourseBatcheDateSession[CourseBatche]['+array[6]+'][ClassVenue]['+array[4]+'][date][]" id="course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_date_'+i+'" type="text" placeholder="Date">\n\
<div class="errorMessage" id="error_venue_'+array[4]+'_batch_'+array[6]+'_daySession_date_s'+i+'" style="display:none">Start date cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker"><div class="clear"></div><input onblur="checkValueEmpty(this.id);"  name="CourseBatcheDateSession[CourseBatche]['+array[6]+'][ClassVenue]['+array[4]+'][time_from][]" id="course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_time_from_'+i+'" type="text"  onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id);" class=" hastimePicker field small requiredfield"  onchange="timeCheck(this.id);">\n\
 <div class="errorMessage" id="error_course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_time_from_'+i+'" style="display:none">Start time cannot be blank.</div></div>\n\
<div class="insm-col2 bootstrap-timepicker" ><div class="clear"></div>\n\
<input name="CourseBatcheDateSession[CourseBatche]['+array[6]+'][ClassVenue]['+array[4]+'][time_to][]" id="course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_time_to_'+i+'" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id);" class="requiredfield  hastimePicker field small"  type="text"   size="10" value="" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_time_to_'+i+'" style="display:none">End time cannot be blank.</div>\n\
<div class="errorMessage" id="endTime_course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_time_to_'+i+'"></div></div>\n\
<div class="insm-col3 ">  <div class="clear"></div>\n\
<input type="checkbox" class="isdaySesionFlexble" value="1" id="course_venue_'+array[4]+'_batch_'+array[6]+'_daySession_is_flexible_'+i+'" onclick="return isFlexibleDaySession(this.id);" name="CourseBatcheDateSessions[CourseBatche]['+array[6]+'][ClassVenue]['+array[4]+'][is_flexible][]" >\n\
<input type="hidden" name="CourseBatcheDateSession[CourseBatche]['+array[6]+'][ClassVenue]['+array[4]+'][is_flexiblevalue][]" value="0" id="venue_'+array[4]+'_batch_'+array[6]+'_daySession_is_flexiblevalue_'+i+'"/>\n\
</div><div class="clear"></div>';
        }
        $('.venue_'+array[4]+'_batch_'+array[6]+'_dateSession').show();         
        $('.venue_'+array[4]+'_batch_'+array[6]+'_dateSession').html(dateSessionhtml);
        $('.isdaySesionFlexble').fancyfields({
            onCheckboxChange: function (input, isChecked){ 
                array=input.attr("id").split("_");
                if(isChecked==true) { 
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).removeClass("hastimePicker requiredfield");
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).removeClass("hastimePicker requiredfield");
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).val('');
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).val('');
                    $('#error_course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).hide();
                    $('#error_course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).hide();
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_is_flexiblevalue_'+array[8]).val(1);                   
                }else{
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).addClass("hastimePicker  requiredfield ");
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).addClass(" hastimePicker requiredfield ");
                    $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_is_flexiblevalue_'+array[8]).val(0);
                    $('#error_course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).show();
                    $('#error_course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).show();
                
                }
            }
        }); 
    }
}
function timeCheck(id) {
    var array = id.split("_");
    startTime = $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8] + "").val();
    endTime = $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8] + "").val();
    if ((endTime != '') && (startTime != '')) {
        var startTimeArray = startTime.split(" ");
        var endTimeArray = endTime.split(" ");
        var firstValEndTime = endTime.split(":");
        var firstValStartTime = startTime.split(":");
        timeCheckByType(startTimeArray, endTimeArray, firstValStartTime, firstValEndTime, array);
    }

}

function timeCheckByType(startTimeArray, endTimeArray, firstValStartTime, firstValEndTime, array) {
    if ((startTimeArray[1] == endTimeArray[1])) {
        if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) <= 11)) {
            var k = 1;
            if ((parseInt(firstValStartTime[0]) == parseInt(firstValEndTime[0])) && (parseInt(firstValStartTime[1]) >= parseInt(firstValEndTime[1]))) {             
                $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).val('');
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text("End time greater than start time!");
                k = 2;
            }
            if (parseInt(firstValStartTime[0]) > parseInt(firstValEndTime[0])) {
                $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).val('');
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text("End time greater than start time!");
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
                k = 3;
            }
            if (k == 1) {
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text('');
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
            }
        }
        else if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) >= 11)) {
            if ((parseInt(firstValStartTime[0]) == parseInt(firstValEndTime[0])) && (parseInt(firstValStartTime[1]) >= parseInt(firstValEndTime[1]))) {
                $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).val('');
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text("End time greater than start time!");
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
            }
            if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) >= 11)) {

                $("#course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).val('');
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text("End time can not be use 24hours !");
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
            }

            else {
                $("#endTime_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).text('');
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_"+array[4]+"_daySession_time_from_" + array[8]).hide();
            }
        }

    }
    else {

        $('#endTime_course_venue_' + array[2] + '_batch_end_time_' + array[6]).text('');
        $('#error_course_venue_' + array[2] + '_batch_end_time_' + array[6]).hide();
        $('#error_course_venue_' + array[2] + '_batch_start_time_' + array[6]).hide();
    }


}

function checkDate(id) {
    var array = id.split("_");   
    var startDate = $('#course_venue_'+array[2]+'_batch_start_date_'+array[6]).val();
    var endDate = $('#course_venue_'+array[2]+'_batch_end_date_'+array[6]).val();
    if (startDate != '' && endDate != '') {
        var startDateArray = startDate.split(" ");
        var endDateArray = endDate.split(" ");
        if ((startDateArray[0] >= endDateArray[0]) && (startDateArray[1] == endDateArray[1])) {
            $('#course_venue_'+array[2]+'_batch_end_date_'+array[6]).val('');
            $('#enddate_course_venue_'+array[2]+'_batch_end_date_'+array[6]).text("End date greater than start date!");
        }
        if ((startDateArray[0] < endDateArray[0]) && (startDateArray[1] == endDateArray[1])) {
            $('#error_course_venue_'+array[2]+'_batch_end_date_'+array[6]).text('');
            $('#enddate_course_venue_'+array[2]+'_batch_end_date_'+array[6]).text('');
        }
    }
}


 
function datedaySesionisFlexble(id,isChecked){
    array=id.split("_");
    if(isChecked==true) { 
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).removeClass("hastimePicker requiredfield");
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).removeClass("hastimePicker requiredfield");
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).val('');
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).val('');                   
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_is_flexiblevalue_'+array[8]).val('1');                   
    }else{
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_from_'+array[8]).addClass("hastimePicker  requiredfield ");
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_time_to_'+array[8]).addClass(" hastimePicker requiredfield ");
        $('#course_venue_'+array[2]+'_batch_'+array[4]+'_daySession_is_flexiblevalue_'+array[8]).val(0);
    }
}

function showDateSessionAndDaySesion(id){
    array=id.split("_");
    if(array[4]!='dateSession'){
        $("#venue_"+array[1]+"_batch_"+array[3]+"_dateSession").fancyfields("clean"); 
        $("#no_of_session_venue_"+array[1]+"_batch_"+array[3]).removeClass("requiredfield");        
        addSesionOnRadioChange(id);
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession_html").html('');
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession_addSesion").show();
        $(".venue_"+array[1]+"_batch_"+array[3]+"_dateSession").hide();                    
        $(".venue_"+array[1]+"_batch_"+array[3]+"_dateNoSession").hide();
    }else{      
        $("#no_of_session_venue_"+array[1]+"_batch_"+array[3]).addClass("requiredfield");
        $("#venue_"+array[1]+"_batch_"+array[3]+"_daySession_show_hide").fancyfields("clean");
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession_html").html('');
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession_show_hide").html('');
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession_addSesion").hide();
        $(".venue_"+array[1]+"_batch_"+array[3]+"_daySession").html('');
        $(".venue_"+array[1]+"_batch_"+array[3]+"_dateNoSession").show();
        $("#no_of_session_venue"+array[1]+"_batch_"+array[3]).val('');
        $(".venue_"+array[1]+"_batch_"+array[3]+"_dateSession").html(''); 
        $(".venue_"+array[1]+"_batch_"+array[3]+"_dateSession").show(); 
    }
}
